package com.qidian.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.pojo.pro.ProProcess;
import com.qidian.mes.pojo.pro.ProProcessContent;
import com.qidian.mes.pojo.pro.ProRouteProcess;
import com.qidian.mes.pro.mapper.ProProcessMapper;
import com.qidian.mes.pro.mapper.ProRouteProcessMapper;
import com.qidian.mes.pro.service.ProRouteProcessService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.IllegalFormatCodePointException;
import java.util.List;

/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/11/2 19:01
 * @Description
 **/
@Service
public class ProRouteProcessServiceImpl implements ProRouteProcessService {
    @Autowired
    ProRouteProcessMapper proRouteProcessMapper;
    @Autowired
    ProProcessMapper proProcessMapper;
    @Override
    public MESResult save(ProRouteProcess proRouteProcess) {
        ProProcess process=new ProProcess();
        process.setProcessName(proRouteProcess.getProcessName());
        process=proProcessMapper.selectByProcessName(process);
        proRouteProcess.setProcessId(process.getProcessID());
        proRouteProcess.setProcessName(process.getProcessName());
        proRouteProcess.setProcessCode(process.getProcessCode());
        System.err.println(proRouteProcess);
        if (proRouteProcessMapper.insert(proRouteProcess)==1)
        {
            return MESResult.ok();
        }
        else
        {
            return MESResult.fail();
        }

    }

    @Override
    public MESResult selectByrouteId(int page, int limit, Long routeId) {
        PageHelper.startPage(page,limit);
        List<ProRouteProcess> list=proRouteProcessMapper.selectByrouteId(routeId);
        PageInfo<ProRouteProcess> pageInfo=new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult deleteRouteProcess(Long recordId) {
        System.err.println(recordId+"ssssssssss");
        if (proRouteProcessMapper.deleteRouteProcess(recordId)==1){
            return MESResult.ok();
        }
        else{
            return MESResult.fail();
        }

    }

    @Override
    public MESResult update(ProRouteProcess proRouteProcess) {
       if (proRouteProcessMapper.update(proRouteProcess)==1){
           return MESResult.ok();
       }
       else{
           return MESResult.fail();
       }
    }
}
